<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" 
		href="${pageContext.request.contextPath}/themes/icon.css">
<link rel="stylesheet" 
		href="${pageContext.request.contextPath}/themes/bootstrap/easyui.css">
<script type="text/javascript" 
		src="${pageContext.request.contextPath}/js/jquery.js"></script>
<script type="text/javascript" 
		src="${pageContext.request.contextPath}/js/jquery.easyui.min.js"></script>
<script type="text/javascript" 
		src="${pageContext.request.contextPath}/js/easyui-lang-zh_CN.js"></script>
</head>
<script type="text/javascript">
	$(function () {
		$('#studentTable').datagrid({    
		    url:'selectStudent', 
		    pagination:true,
		    pagesize:5,
		    pageList:[5,10],
		    rownumbers:true,
		    title:'学生信息',
		    columns:[[   
		    	{field:'ck',checkbox:true,width:100},
		        {field:'sid',title:'学号',hidden:true,width:100},    
		        {field:'sname',title:'姓名',width:100},    
		        {field:'sage',title:'年龄',width:100},    
		        {field:'snation',title:'民族',width:100},    
		        {field:'saddress',title:'地址',width:100},    
		        {field:'stel',title:'电话',width:100,align:'right'}    
		    ]] ,
		    toolbar: [{
				iconCls: 'icon-add',
				text:'添加',
				handler: function(){
					$('#add1').window('open');
					}
			},'-',{
				iconCls: 'icon-edit',
				text:'修改',
				handler: function(){
					var row  = $('#studentTable').datagrid('getSelected');
					$('#add').window('open');
					$('#addForm').form('load', row);
					}
			},'-',{
				iconCls: 'icon-remove',
				text:'删除',
				handler: function(){
					var rows  = $('#studentTable').datagrid('getSelections');
					var sids = [];
					for (var i = 0; i < rows.length; i++) {
						sids.push(rows[i].sid);
					}
					$.ajax({
						url:'delStudent',
						type:'post',
						dataType:'text',
						data:{'sids':sids},
						success:function(data){
							$.messager.alert('消息提示',data,'info',function(){
					    		$('#studentTable').datagrid('reload');
					    	}); 
						}
					})
					}
			}]

		    
		}); 
		$('#add').window({   
			title:'修改学生',
			shadow:true,
		    width:600,    
		    height:400,    
		    modal:true   
		});
		$('#add1').window({   
			title:'添加学生',
			shadow:true,
		    width:600,    
		    height:400,    
		    modal:true   
		});
		$('#add').window('close');
		$('#sname').textbox({    
		    height:30
		})
		$('#sage').textbox({    
		    height:30
		})
		$('#snation').textbox({    
		    height:30
		})
		$('#saddress').textbox({    
		    height:30
		})
		$('#stel').textbox({    
		    height:30
		})
		$('#log').linkbutton({    
		    iconCls: 'icon-ok',
		   
		});
		$('#log').bind('click', function(){    
	    	$('#addForm').submit();    
	    }); 
		$('#addForm').form({    
		    url:'updateStudent',
		    success:function(data){    
		    	$.messager.alert('消息提示',data,'info',function(){
		    		$('#addForm').form('clear');
		    		$('#add').window('close');
		    		$('#studentTable').datagrid('reload');
		    	}); 
			}    
		});    
		
		$('#add1').window('close');
		$('#sname1').textbox({    
		    height:30,
		    prompt:'请输入姓名'
		})
		$('#sage1').textbox({    
		    height:30,
		    prompt:'请输入年龄'
		})
		$('#snation1').textbox({    
		    height:30,
		    prompt:'请输入民族'
		})
		$('#saddress1').textbox({    
		    height:30,
		    prompt:'请输入地址'
		})
		$('#stel1').textbox({    
		    height:30,
		    prompt:'请输入电话'
		})
		$('#log1').linkbutton({    
		    iconCls: 'icon-ok',
		   
		});
		$('#log1').bind('click', function(){    
	    	$('#addForm1').submit();    
	    }); 
		$('#addForm1').form({    
		    url:'addStudent',
		    success:function(data){    
		    	$.messager.alert('消息提示',data,'info',function(){
		    		$('#addForm1').form('clear');
		    		$('#add1').window('close');
		    		$('#studentTable').datagrid('reload');
		    	}); 
			}    
		});    

		

	})
</script>
<body>
<div id="add">
		<div style="margin-left: 150px;margin-top: 90px;">
		<form id="addForm" method="post">   
    		<input id="sid" name="sid" type="hidden" style="width:300px ">
    		<br>
    		<input id="sname" name="sname" type="text" style="width:300px">
    		<br>
    		<input id="sage" name="sage" type="text" style="width:300px ">
    		<br>
    		<input id="snation" name="snation" type="text" style="width:300px">
    		<br>
    		<input id="saddress" name="saddress" type="text" style="width:300px ">
    		<br>
    		<input id="stel" name="stel" type="text" style="width:300px">
		</form> 
			<br>
		<a id="log" href="#">提交</a>
		</div>
	</div>
	<div id="add1">
		<div style="margin-left: 150px;margin-top: 90px;">
		<form id="addForm1" method="post">   
    		
    		<input id="sname1" name="sname" type="text" style="width:300px">
    		<br>
    		<input id="sage1" name="sage" type="text" style="width:300px ">
    		<br>
    		<input id="snation1" name="snation" type="text" style="width:300px">
    		<br>
    		<input id="saddress1" name="saddress" type="text" style="width:300px ">
    		<br>
    		<input id="stel1" name="stel" type="text" style="width:300px">
		</form> 
			<br>
		<a id="log1" href="#">提交</a>
		</div>
	</div>
	
	<div>
		<table id="studentTable"></table>  
	</div>

</body>
</html>